"use strict";

var timeout;
app.controller("QueryPaymentPlatformController", ["$scope", "$modal", "$timeout", "RESTService",
    function($scope,   $modal,   $timeout,   RESTService) {
        $scope.servReqs = [];
        $scope.item = {
            startDate: moment(new Date()).format('YYYY-MM-01'),
            finishDate: moment(new Date()).format('YYYY-MM-DD')
        }
        $scope.summaryOfAmount_Platform = 0;
        var loadListData = function() {
            var startDate = moment($scope.item.startDate).format('YYYY-MM-DD');
            var finishDate = moment($scope.item.finishDate).format('YYYY-MM-DD');

            RESTService.getResponse("/rest/servreq/getSR4PaidPlatform?paid_Platform=true&pageNo=1&pageSize=1000" +
                "&startDate=" + startDate + "&finishDate=" + finishDate).then(function(response) {
                $scope.servReqs = response;

                $scope.summaryOfAmount_Platform = 0;

                angular.forEach(response, function(item) {
                    $scope.summaryOfAmount_Platform += item.amount_Platform;
                });

            });
        }
        $scope.init = function() {
            loadListData();
        }
        $scope.query = function() {
            loadListData();
        }
    }
]);
